package clientatm;

import java.io.*;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BankomatMethods {
    public enum Keywords {
        ;
        public static final String TRY_CONNECTION = "ready... try Connection to server\n";
        public static final String NO_CONNECTION = "NO CONNECTION TO SERVER. TRY LATER\n";
        public static final String INFO = "\nI N F O R M A T I O N\n";
        public static final String ENTER_MENU = "\nTo continue type      1\n\nFor information type  2\n\nTo exit enter         0 \n";
        public static final String INSTRUCTION_TO_SHOW = "SHOW";
    }
    ;

    public String connectToServerAndProvideTransaction(Integer inputdata, String somecach, String readline, String userCard) throws IOException {
        String str = null;
        String showData;
        System.out.println(Keywords.TRY_CONNECTION);
        try {
            Socket socket = new Socket("127.0.0.1", 7001);
            OutputStream outputS = socket.getOutputStream();
            DataOutputStream outputData = new DataOutputStream(outputS);
            showData = new SimpleDateFormat("hh.mm.ss").format(new Date());
            outputData.writeUTF("[" + showData + "] <" + inputdata + ">*<" + userCard + "> # " + readline + "want " + somecach + "            ");

            InputStream inputS = socket.getInputStream();
            DataInputStream inputData = new DataInputStream(inputS);
            str = inputData.readUTF();

            System.out.print("\n" + str + "\n");
        } catch (Exception x) {
            clearUserScreen();
            System.out.println(Keywords.NO_CONNECTION);
        } finally {
            return str;
        }
    }

    public boolean getInfo() {
        clearUserScreen();
        System.out.println(Keywords.INFO);
        return true;
    }

    public boolean clearUserScreen() {
        for (int i = 0; i < 50; i++) {
            System.out.println("\n");
        }
        return true;
    }

    public static boolean sayHello() {
        System.out.println(Keywords.ENTER_MENU);
        return true;
    }
}
